package m.jclecai.com.activity;

import android.content.Context;
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.LinearLayout;

import butterknife.BindView;
import m.jclecai.com.R;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.fragment.goldManager.GoldDetailFragment;
import m.jclecai.com.fragment.goldManager.GoldExchangeFragment;

public class GoldManagerActivity extends BaseActivity {


    private static final String IS_SHOW_GOLD_DETAIL = "isShowGoldDetail";

    @BindView(R.id.tl_tablayout)
    TabLayout mTlTablayout;
    @BindView(R.id.vp_view_pager)
    ViewPager mVpViewPager;
    @BindView(R.id.activity_gold_manager)
    LinearLayout mActivityGoldManager;

    public String[] mTitles=new String[]{"金币兑换","金币明细"};

    @Override
    protected int getContentView() {
        return R.layout.activity_gold_manager;
    }

    @Override
    protected void initView() {
        //这里我们对其进行一个搞事情
        setTitle("金币管理");
        leftOptionText("");
    }

    @Override
    protected void initData() {
        //如果我们不想让其滑动的话，我们直接禁用就好了
/*        LinearLayout childAt = (LinearLayout) mTlTablayout.getChildAt(0);
        childAt.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        childAt.setDividerDrawable(getResources().getDrawable(R.drawable.shape_linearlayout_divider));*/

        mVpViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        mTlTablayout.setupWithViewPager(mVpViewPager);

        Intent intent = getIntent();
        boolean isShowGoldDetail = intent.getBooleanExtra(IS_SHOW_GOLD_DETAIL, false);

        if (isShowGoldDetail) {
            mVpViewPager.setCurrentItem(1);
        }else {
            mVpViewPager.setCurrentItem(0);
        }
    }

    @Override
    protected void initListener() {
    }

    public class  MyPagerAdapter extends FragmentPagerAdapter{


        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment=null;
            if(position==0){
                fragment=new GoldExchangeFragment();
            }else if(position==1){
                fragment=new GoldDetailFragment();
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return 2;
        }
    }

    /**
     * 获取GoldManagerActivity的一个Intent
     * @param context
     * @param isShowGoldDetail 进入的时候是否是显示金币明细，默认的是金币兑换
     * @return
     */
    public static Intent getGoldManagerIntent(Context context,boolean isShowGoldDetail){
        Intent intent = new Intent(context,GoldManagerActivity.class);
        intent.putExtra(IS_SHOW_GOLD_DETAIL,isShowGoldDetail);
        return intent;
    }
}
